<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="centre/manage/include :: header">
</head>

<link rel="stylesheet" type="text/css" href="/css/plugins/layui/layui.css"/>
<link href="/css/jquery-select/jquery.searchableSelect.css" rel="stylesheet" type="text/css">
<style>
    .province {
        float: left;
        position: relative;
        width: 150px;
        height: 35px;
        line-height: 35px;
        border: 1px solid #fff;
    }

    .province:hover {
        border: 1px solid #f7e4a5;
        border-bottom: 1px solid #fffec6;
        background: #fffec6;
    }

    .province .cityall {
        margin-top: 10px;
    }

    .province ul {
        list-style: outside none none;
        position: absolute;
        padding: 0;
        background: #fffec6;
        border: 1px solid #f7e4a5;
        display: none;
        width: auto;
        width: 300px;
        z-index: 999999;
        left: -26px;
        top: 33px;
    }

    .province ul li {
        float: left;
        min-width: 60px;
        margin-left: 20px;
        height: 30px;
        line-height: 30px;
    }

    .province .checkbox-inline {
        padding-top: 0;
    }

    h3, h4, h5 {
        margin: 5px 0;
        font-weight: 600;
    }

    input[type=email], input[type=url], input[type=search], input[type=tel],
    input[type=color], input[type=text], input[type=password], input[type=datetime],
    input[type=datetime-local], input[type=date], input[type=month], input[type=time],
    input[type=week], input[type=number], textarea {
        border-radius: 0 !important;
        color: #858585;
        background-color: #FFF;
        border: 1px solid #D5D5D5;
        padding: 5px 4px 6px;
        font-size: 14px;
        font-family: inherit;
        -webkit-box-shadow: none !important;
        box-shadow: none !important;
        -webkit-transition-duration: .1s;
        transition-duration: .1s;
    }

    .spectable td, .spectable th {
        border: 1px solid #ccc;
        vertical-align: middle;
        text-align: center;
    }

    .spectable th {
        font-weight: bold;
    }

    .spectableinput {
        text-align: center;
    }

    .f {
        border-color: #b94a48;
        -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
        -moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
        box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
    }

    .table.table-bordered tr th, .table.table-bordered tr td {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    select {
        padding: 3px 4px;
        height: 30px;
    }

    .form-group .goods-thumb {
        float: left;
        margin-right: 10px;
        width: 50px;
        height: 50px;
        background-position: 50%;
        background-size: cover;
    }

    .form-group .goods-control {
        width: 400px;
        margin: 10px;
    }

    .form-group .goods-actions {
        float: right;
        margin-right: 20px;
    }

</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <!--			<form class="form-horizontal m-t" id="signupForm">-->
            <div class="form-horizontal m-t">
                <input type="hidden" id="activityId" name="activityId" th:value="${activityId}">
                <div class="form-group">
                    <ul class="nav nav-arrow-next nav-tabs" id="myTab">
                        <li class="active"><a href="#tab_basic">基础设置</a></li>
                        <li><a href="#tab_des">商品设置</a></li>
                    </ul>
                </div>
                <div class="tab-content" style="border: 0px;">
                    <div class="tab-pane active" id="tab_basic">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">活动名称:</label>
                            <div class="col-sm-6">
                                <input id="activityName" name="activityName" placeholder="必填：活动名称"
                                       class="form-control" type="text" maxlength="100"
                                       th:value="${activity.activityName}">
                            </div>
                            <label class="col-sm-2 control-label"
                                   style="text-align: left;color:red;">*拼团名称(50个汉字以内)</label>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">开始时间:</label>
                            <div class="col-sm-6">
                                <input type="text" class=" form-control"
                                       id="startTime" name="startTime" placeholder="开始时间"
                                       onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
                                       style="background-color: #fff;" readonly="readonly"
                                       th:value="${#dates.format(activity.startTime, 'yyyy-MM-dd HH:mm:ss')}"/>
                            </div>
                            <label class="col-sm-2 control-label" style="text-align: left;color:red;">*开始时间</label>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">结束时间:</label>
                            <div class="col-sm-6">
                                <input type="text" class=" form-control"
                                       id="endTime" name="endTime" placeholder="结束时间"
                                       onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
                                       style="background-color: #fff;" readonly="readonly"
                                       th:value="${#dates.format(activity.endTime, 'yyyy-MM-dd HH:mm:ss')}"/>
                            </div>
                            <label class="col-sm-2 control-label" style="text-align: left;color:red;">*结束时间</label>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">活动规则:</label>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">条件类型*:</label>
                            <div class="col-sm-8">
                                <label class="radio-inline">
                                    <input type="radio" name="rule" value="1" th:checked="${activity.rule} == 1"/>满X元
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="rule" value="2" th:checked="${activity.rule} == 2"/>满X件
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">活动方式*:</label>
                            <div class="col-sm-8">
                                <label class="radio-inline">
                                    <input type="radio" name="mode" value="1" th:checked="${activity.mode} == 1"/>单层级赠送多次
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="mode" value="2" th:checked="${activity.mode} == 2"/>多层级赠送一次
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">赠送条件设置*:</label>
                            <div class="col-sm-8">
                                每满
                                <input type="text" class=" form-control" id="cond" name="cond"
                                       th:value="${activity.cond}"
                                       style="background-color: #fff;"/>元
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">赠送条件设置*:</label>
                            <div class="col-sm-8">
                                每人最多参与
                                <input type="text" class=" form-control" id="joinNum" name="joinNum"
                                       style="background-color: #fff;" th:value="${activity.joinNum}"/>次（输入0代表不设置上限）
                            </div>
                        </div>
                        <div class="form-group">
                            <!--<div class="col-md-12">选择赠送的商品</div>-->
                            <div class="col-md-12 col-xs-6" id="choseGoods">
                                <a onclick="chooseProduct()">点击选择赠送商品</a>
                            </div>
                            <div class="form-group">
                                <table id="giftProductListTable" data-mobile-responsive="true"></table>
                            </div>
                        </div>


                        <div class="form-group text-center">
                            <div class="col-sm-8 col-sm-offset-2">
                                <button class="btn btn-primary" onclick="nextStep()">
                                    <i class="fa fa-check"></i>下一步
                                </button>
                            </div>
                        </div>
                    </div>
                    <!-- 商品选择开始 -->
                    <div class="tab-pane" id="tab_des">
                        &nbsp;
                        <div class="form-group">
                            <label class="col-sm-2 control-label">活动范围:</label>
                            <div class="col-sm-8">
                                <label class="radio-inline">
                                    <input type="radio" name="range" value="1" checked/>全部商品参与
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="range" value="2"/>指定商品参与
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="range" value="3"/>指定商品不参与
                                </label>
                            </div>
                        </div>

                        <div class="form-group good-choose">
                            <!--<div class="col-md-12">选择活动商品</div>-->
                            <input type="hidden" id="groupPrice">
                            <div class="col-md-12 col-xs-6" id="addGoods">
                                <a onclick="chooseJoinProduct()">点击选择活动商品</a>
                            </div>
                        </div>
                        <div class="form-group">
                            <table id="joinProductListTable" data-mobile-responsive="true"></table>
                        </div>

                        <div class="form-group text-center">
                            <div class="col-sm-8 col-sm-offset-2">
                                <!--														<button type="submit" class="btn btn-primary"><i class="fa fa-check"></i>提交</button>-->
                                <button class="btn btn-primary" onclick="saveProduct()">
                                    <i class="fa fa-check"></i>提交
                                </button>
                                <!--														<div class="btn btn-danger" onclick="reset()">-->
                                <!--															<i class="fa fa-remove"></i> 重置-->
                                <!--														</div>-->
                            </div>
                        </div>
                    </div>
                </div>

                <div id="goodsSeckillPrice" style="display:none;    margin-top: 1rem;">
                    <div>
                        <label class="col-sm-4">活动价格:</label>
                        <div class="col-sm-8">
                            <input id="seckillPrice" name="displayorder" placeholder="必填：活动价格"
                                   class="form-control" type="number" value="0">
                        </div>
                    </div>
                    <div>
                        <label class="col-sm-4">活动库存:</label>
                        <div class="col-sm-8">
                            <input type="number"
                                   id="seckillStotal" name="seckillStotal" placeholder="必填:活动库存"/>
                        </div>

                    </div>
                </div>

            </div>
            <!--			</form>-->
        </div>
    </div>
</div>

<div th:include="centre/manage/include::footer"></div>
<script type="text/javascript" src="/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/js/ueditor/custom.js?v=2"></script>
<script type="text/javascript" src="/js/appjs/product/AreaData.js"></script>
<script type="text/javascript" src="/public/ace/js/ace-extra.js"></script>
<script type="text/javascript" src="/js/plugins/layui/layui.js"></script>
<script type="text/javascript" src="/js/plugins/layer/layer.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script src="/js/jquery-select/jquery.searchableSelect.js"></script>
<script type="text/javascript" src="/js/plugins/layui/layui.js"></script>
<script type="text/javascript">


    // var activityId = [[${activityId}]];
    // var activityId = [[${activityId}]];
    // console.info('====activityId===='+activityId);
    var joinGoodsData = [];
    console.info('====joinGoodsData=====' + joinGoodsData);
    var data = [];
    console.info('====data=====' + data);

    var prefix = "/activity/manage";

    $(function () {
        // tab切换
        $('#myTab a').click(function (e) {
            e.preventDefault();
            $('#myTab li').each(function () {
                $(this).removeClass('active')
            })
            $('.tab-content .tab-pane').each(function () {
                $(this).removeClass('active')
            })
            $(this).parent().addClass('active')
            id = $(this).attr('href')
            $(id).addClass('active');
        });
        giftProductListTableTableReload();
        joinProductListTableTableReload();
    })

    // var data = [];

    function giftProductListTableTableReload() {
        $('#giftProductListTable').bootstrapTable('destroy');
        localTable = $('#giftProductListTable').bootstrapTable({
            method: 'get', // 服务器数据的请求方式 get or post
            url: prefix + "/listAllProduct", // 服务器数据的加载地址
            showRefresh: true,
            // showToggle : true,
            iconSize: 'outline',
            // toolbar: '#exampleToolbar',
            striped: true, // 设置为true会有隔行变色效果
            dataType: "json", // 服务器返回的数据类型
            pagination: true, // 设置为true会在底部显示分页条
            pageList: [10, 20, 50],
            // queryParamsType : "limit",
            // //设置为limit则会发送符合RESTFull格式的参数
            singleSelect: false, // 设置为true将禁止多选
            // contentType : "application/x-www-form-urlencoded",
            // //发送到服务器的数据编码类型
            pageSize: 10, // 如果设置了分页，每页数据条数
            pageNumber: 1, // 如果设置了分布，首页页码
            // search : true, // 是否显示搜索框
            showColumns: true, // 是否显示内容下拉框（选择显示的列）
            sidePagination: "server", // 设置在哪里进行分页，可选值为"client" 或者
            // "server"
            queryParams: function (params) {
                return {
                    limit: params.limit,
                    offset: params.offset,
                    startDate: $.trim($("#startDate").val()),
                    endDate: $.trim($("#endDate").val()),
                    activityId: $.trim($("#activityId").val()),
                    type: 4
                };
            },
            columns: [
                {
                    field: 'id', // 列字段名
                    title: 'ID' // 列标题
                },
                {
                    field: 'productId',
                    title: '商品ID' // 列标题
                },
                {
                    field: 'centreId',
                    hidden: true
                },
                {
                    field: 'productName',
                    title: '商品标题'
                },
                {
                    field: 'marketprice',
                    title: '价格'
                },
                {
                    field: 'costprice',
                    title: '成本价'
                },
                {
                    field: 'total',
                    title: '库存',
                    formatter: function (value, row, index) {
                        var title = row.title;
                        var str = '<span class="btn btn-xs btn-warning">' + value + '</span>';
                        return str;
                    }
                },
                {
                    title: '操作',
                    field: 'id',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var e = '<a class="btn  btn-sm '
                            + '" href="#" mce_href="#" title="选择规格" onclick="showSelectGiftGoods(\''
                            + value
                            + '\',0)"><i class="fa fa-edit"></i>选择规格</a>'
                            + '<a class="btn  btn-sm '
                            + '" href="#" mce_href="#" title="删除" onclick="remove(\''
                            + value
                            + '\')"><i class="fa fa-edit"></i>删除</a>';

                        return e;
                    }
                }],
            onLoadSuccess: function () {
            },
            onLoadError: function () {
                showTips("数据加载失败！");
            }
        });
    }


    function joinProductListTableTableReload() {
        $('#joinProductListTable').bootstrapTable('destroy');
        localTable = $('#joinProductListTable').bootstrapTable({
            method: 'get', // 服务器数据的请求方式 get or post
            url: prefix + "/listAllProduct", // 服务器数据的加载地址
            showRefresh: true,
            // showToggle : true,
            iconSize: 'outline',
            // toolbar: '#exampleToolbar',
            striped: true, // 设置为true会有隔行变色效果
            dataType: "json", // 服务器返回的数据类型
            pagination: true, // 设置为true会在底部显示分页条
            pageList: [10, 20, 50],
            // queryParamsType : "limit",
            // //设置为limit则会发送符合RESTFull格式的参数
            singleSelect: false, // 设置为true将禁止多选
            // contentType : "application/x-www-form-urlencoded",
            // //发送到服务器的数据编码类型
            pageSize: 10, // 如果设置了分页，每页数据条数
            pageNumber: 1, // 如果设置了分布，首页页码
            // search : true, // 是否显示搜索框
            showColumns: true, // 是否显示内容下拉框（选择显示的列）
            sidePagination: "server", // 设置在哪里进行分页，可选值为"client" 或者
            // "server"
            queryParams: function (params) {
                return {
                    limit: params.limit,
                    offset: params.offset,
                    startDate: $.trim($("#startDate").val()),
                    endDate: $.trim($("#endDate").val()),
                    activityId: $.trim($("#activityId").val()),
                    type: 3
                };
            },
            columns: [
                {
                    field: 'id', // 列字段名
                    title: 'ID' // 列标题
                },
                {
                    field: 'productId',
                    title: '商品ID' // 列标题
                },
                {
                    field: 'centreId',
                    hidden: true
                },
                {
                    field: 'productName',
                    title: '商品标题'
                },
                {
                    field: 'marketprice',
                    title: '价格'
                },
                {
                    field: 'costprice',
                    title: '成本价'
                },
                {
                    field: 'total',
                    title: '库存',
                    formatter: function (value, row, index) {
                        var title = row.title;
                        var str = '<span class="btn btn-xs btn-warning">' + value + '</span>';
                        return str;
                    }
                },
                {
                    title: '操作',
                    field: 'id',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var e = '<a class="btn  btn-sm '
                            + '" href="#" mce_href="#" title="选择规格" onclick="showSelectJoinGoods(\''
                            + value
                            + '\',1)"><i class="fa fa-edit"></i>选择规格</a>'
                            + '<a class="btn  btn-sm '
                            + '" href="#" mce_href="#" title="删除" onclick="remove(\''
                            + value
                            + '\')"><i class="fa fa-edit"></i>删除</a>';

                        return e;
                    }
                }],
            onLoadSuccess: function () {
            },
            onLoadError: function () {
                showTips("数据加载失败！");
            }
        });
    }

    function giftProductListTableLocalReload() {
        $('#giftProductListTable').bootstrapTable('destroy');
        localTable = $('#giftProductListTable').bootstrapTable({
            data: data,
            striped: true, // 设置为true会有隔行变色效果
            search: false,                      //是否显示表格搜索
            strictSearch: false,
            showColumns: false,
            clickToSelect: true,                //是否启用点击选中行
            uniqueId: "fid",                     //每一行的唯一标识，一般为主键列
            showToggle: false,                   //是否显示详细视图和列表视图的切换按钮
            cardView: false,                    //是否显示详细视图
            detailView: false,                  //是否显示父
            columns: [
                {
                    field: 'id', // 列字段名
                    title: 'ID' // 列标题
                },
                {
                    field: 'productId',
                    title: '商品ID' // 列标题
                },
                {
                    field: 'centreId',
                    hidden: true
                },
                {
                    field: 'productName',
                    title: '商品标题'
                },
                {
                    field: 'marketprice',
                    title: '价格'
                },
                {
                    field: 'costprice',
                    title: '成本价'
                },
                {
                    field: 'total',
                    title: '库存',
                    formatter: function (value, row, index) {
                        var title = row.title;
                        var str = '<span class="btn btn-xs btn-warning">' + value + '</span>';
                        return str;
                    }
                },
                {
                    title: '操作',
                    field: 'id',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var e = '<a class="btn  btn-sm '
                            + '" href="#" mce_href="#" title="选择规格" onclick="showSelectGiftGoods(\''
                            + value
                            + '\',0)"><i class="fa fa-edit"></i>选择规格</a>'
                            + '<a class="btn  btn-sm '
                            + '" href="#" mce_href="#" title="删除" onclick="remove(\''
                            + value
                            + '\')"><i class="fa fa-edit"></i>删除</a>';

                        return e;
                    }
                }],
            onLoadSuccess: function () {
            },
            onLoadError: function () {
                showTips("数据加载失败！");
            }
        });
    }

    function joinProductListTableLocalReload() {
        $('#joinProductListTable').bootstrapTable('destroy');
        localTable = $('#joinProductListTable').bootstrapTable({
            data: joinGoodsData,
            striped: true, // 设置为true会有隔行变色效果
            search: false,                      //是否显示表格搜索
            strictSearch: false,
            showColumns: false,
            clickToSelect: true,                //是否启用点击选中行
            uniqueId: "fid",                     //每一行的唯一标识，一般为主键列
            showToggle: false,                   //是否显示详细视图和列表视图的切换按钮
            cardView: false,                    //是否显示详细视图
            detailView: false,                  //是否显示父
            columns: [
                {
                    field: 'id', // 列字段名
                    title: 'ID' // 列标题
                },
                {
                    field: 'productId',
                    title: '商品ID' // 列标题
                },
                {
                    field: 'centreId',
                    hidden: true
                },
                {
                    field: 'productName',
                    title: '商品标题'
                },
                {
                    field: 'marketprice',
                    title: '价格'
                },
                {
                    field: 'costprice',
                    title: '成本价'
                },
                {
                    field: 'total',
                    title: '库存',
                    formatter: function (value, row, index) {
                        var title = row.title;
                        var str = '<span class="btn btn-xs btn-warning">' + value + '</span>';
                        return str;
                    }
                },
                {
                    title: '操作',
                    field: 'id',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var e = '<a class="btn  btn-sm '
                            + '" href="#" mce_href="#" title="选择规格" onclick="showSelectJoinGoods(\''
                            + value
                            + '\',1)"><i class="fa fa-edit"></i>选择规格</a>'
                            + '<a class="btn  btn-sm '
                            + '" href="#" mce_href="#" title="删除" onclick="remove(\''
                            + value
                            + '\')"><i class="fa fa-edit"></i>删除</a>';

                        return e;
                    }
                }],
            onLoadSuccess: function () {
            },
            onLoadError: function () {
                showTips("数据加载失败！");
            }
        });
    }

    function closeDow() {
        var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
        parent.layer.close(index);
    }

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#timestart', type: 'datetime'
        });

        laydate.render({
            elem: '#timeend', type: 'datetime'
        });

        laydate.render({
            elem: '#upStartTime', type: 'datetime'
        });

        laydate.render({
            elem: '#upEndTime', type: 'datetime'
        });


    })

    function nextStep() {
        $('#myTab a[href="#tab_des"]').trigger("click");
    }

    /**
     * 选择商品
     */
    function chooseProduct() {
        // iframe层
        layer.open({
            id: 'group_add',
            type: 2,
            title: '选择商品',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['90%', '90%'],
            content: prefix + '/toChooseProduct' // iframe的url
        });
    }

    /**
     * 选择商品
     */
    function chooseJoinProduct() {
        // iframe层
        layer.open({
            id: 'group_add',
            type: 2,
            title: '选择商品',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['90%', '90%'],
            content: prefix + '/toChooseJoinProduct' // iframe的url
        });
    }

    /**
     * 选择商家
     */
    function chooseCentre() {

        // iframe层
        layer.open({
            id: 'choose_centre',
            type: 2,
            title: '选择店铺',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['70%', '80%'],
            content: "/centre/manage/chooseCentre" // iframe的url
        });
    }

    function checkoption() {
        var full = true;
        if ($("#hasoption").get(0).checked) {
            $(".spec_title").each(function (i) {
                if ($(this).val() == '' || $(this).val() == undefined) {
                    layer.alert("请输入规格名称!", {icon: 5});
                    full = false;
                    return false;
                }
            });
            $(".spec_item_title").each(function (i) {
                if ($(this).val() == '' || $(this).val() == undefined) {
                    layer.alert("请输入规格项名称!", {icon: 5});
                    full = false;
                    return false;
                }
            });
        }
        if (!full) {
            return false;
        }
        return full;
    }

    var row = {};

    function chooseProductCallback(row, isJoinProduct) {
        // var baseHtml = '<a class="goods-thumb" href="' + row.thumb + '" target="_blank" rel="noopener noreferrer" style="background-image: url(' + row.thumb + ');"></a>';
        // baseHtml = baseHtml + '<div class="goods-control"><div class="goods-info"><div class="goods-actions"><a class="opt" onclick="editProduct(' + row.id + ')">编辑</a>&nbsp;&nbsp;<a class="opt" onclick="deleteProduct()">删除</a></div></div>';
        // baseHtml = baseHtml + '<h3 class="goods-title">' + row.title + '</h3>';
        // baseHtml = baseHtml + '<span class="seckill-price">团购价：未设置</span><input type="hidden" id="groupPrice">';
        // baseHtml = baseHtml + '<span class="seckill-stock">库存：未设置</span><input type="hidden" id="stock">';
        // var endhtml = '</div>';
        // var specItemSelect = '<a class="opt" onclick="showSelectGiftGoods(' + row.id + ')">选择规格</a>';

        row.productId = row.id;
        row.productName = row.title;
        this.row = row;

        if (isJoinProduct != 1) {
            var rows = $("#giftProductListTable").bootstrapTable('getData');//行的数据
            var rowData = {};
            var dataIndex = 0;
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].id == row.id) {
                    rowData = rows[i];
                    dataIndex = i;
                    break;
                }
            }

            console.info(row);
            if (rows.length == 0 || !rowData.id) {
                rows.push(row);
                this.data = rows;
                giftProductListTableLocalReload();
            } else {
                $("#giftProductListTable").bootstrapTable("updateRow", {
                    index: dataIndex,//更新行索引，0起始
                    replace: true,//合并or替换行数据，true替换，false合并，默认false
                    row: row
                });
            }
        } else {
            var rows = $("#joinProductListTable").bootstrapTable('getData');//行的数据
            var rowData = {};
            var dataIndex = 0;
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].id == row.id) {
                    rowData = rows[i];
                    dataIndex = i;
                    break;
                }
            }

            console.info(row);
            if (rows.length == 0 || !rowData.id) {
                rows.push(row);
                this.joinGoodsData = rows;
                joinProductListTableLocalReload();
            } else {
                $("#joinProductListTable").bootstrapTable("updateRow", {
                    index: dataIndex,//更新行索引，0起始
                    replace: true,//合并or替换行数据，true替换，false合并，默认false
                    row: row
                });
            }
        }

        // giftProductListTableTableReload();
        // baseHtml = baseHtml + specItemSelect + endhtml;
        // if (row.hasoption == 1) {
        //     baseHtml = baseHtml + endhtml;
        // }
        // $("#giftGoodsInfo").append(baseHtml);

        // $("#addGoods").hide();
        // if (row.hasoption == 1) {//有规格，展示规格
        //     showSeckillPriceStock(row.id);
        // } else {//没有规格，展示价格
        //     showSeckillPrice();
        // }
    }

    function editProduct() {
        if (this.row.hasoption == 1) {
            showSeckillPriceStock(this.row.id);
        } else {
            showSeckillPrice();
        }
    }

    function chooseCentreCallback(row) {
        console.log(row);
        $("#centreId").val(row.centreId);
        $("#centreName").val(row.shortName);
    }

    function deleteProduct() {
        $("#goodsInfo").empty();
        $("#addGoods").show();

        localStorage.removeItem("productSKU");
    }

    function showSeckillPrice() {
        if (this.row) {
            $("#seckillPrice").val(this.row.marketprice);
            $("#seckillStotal").val(this.row.total);
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            shadeClose: false,
            content: $("#goodsSeckillPrice"),
            btn: ['确定', '取消'],
            yes: function (index, layero) {

                $(".seckill-price").text("拼团价: " + $("#seckillPrice").val())
                $(".seckill-stock").text("库存: " + $("#seckillStotal").val());
                $("#groupPrice").val($("#seckillPrice").val());
                $("#stock").val($("#seckillStotal").val());

                layer.close(index);
            }
            , cancel: function () {
                //右上角关闭回调
                return true;// 开启该代码可禁止点击该按钮关闭
            }
        });

    }

    /**
     * 选择sku 设置类型
     */
    var index = 0;

    function showSeckillPriceStock(id) {

        index = layer.open({
            type: 2,
            title: '选择活动赠品',
            closeBtn: 0,
            area: ['100%', '100%'],
            shadeClose: false,
            content: prefix + '/toProductGroupStockSetting?productCentreId=' + id
        });
    }


    /**
     * 选择sku 设置类型
     */
    var giftGoodsIndex = 0;

    function showSelectGiftGoods(productId) {

        giftGoodsIndex = layer.open({
            type: 2,
            title: '选择活动赠品',
            closeBtn: 0,
            area: ['100%', '100%'],
            shadeClose: false,
            content: prefix + '/toGiftProductSpecSelect?productId=' + productId
        });
    }

    function showSelectJoinGoods(productId) {

        giftGoodsIndex = layer.open({
            type: 2,
            title: '选择活动赠品',
            closeBtn: 0,
            area: ['100%', '100%'],
            shadeClose: false,
            content: prefix + '/toJoinProductSpecSelect?productId=' + productId
        });
    }

    function remove(productId) {
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            shadeClose: false,
            content: '确定删除该赠品？',
            btn: ['确定', '取消'],
            yes: function (index, layero) {

                var rows = $("#giftProductListTable").bootstrapTable('getData');//行的数据
                var newRows = [];
                var rowData = {};
                var dataIndex = 0;
                for (var i = 0; i < rows.length; i++) {
                    if (rows[i].id != productId) {
                        newRows.push(rows[i]);
                    }
                }

                this.data = newRows;
                // giftProductListTableTableReload();
                $('#giftProductListTable').bootstrapTable('refresh');

                layer.close(index);
            }
            , cancel: function () {
                //右上角关闭回调
                return true;// 开启该代码可禁止点击该按钮关闭
            }
        });

    }

    function callBack(data, isJoinProduct) {

        console.info(data);
        var minPrice = 0;
        var stock = 0;
        for (var i = 0; i < data.length; i++) {
            var groupPrice = data[i].groupPrice;
            if (i == 0) {
                minPrice = groupPrice
            }
            stock = Number(stock) + Number(data[i].stock);
        }
        // $(".seckill-price").text("团购杀价: " + "￥" + minPrice);
        // $(".seckill-stock").text("库存: " + stock);
        //
        // $("#groupPrice").val(minPrice);
        // $("#stock").val(stock);


        if (data.length > 0) {
            if (isJoinProduct == 1) {
                localStorage.setItem("joinProductSKU", JSON.stringify(data));
            } else {
                localStorage.setItem("productSKU", JSON.stringify(data));
            }
        }

    }

    function callClose() {
        layer.close(index);
        layer.close(giftGoodsIndex);
    }

    $.validator.setDefaults({
        submitHandler: function () {
            saveProduct();
        }
    });

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                activityName: {
                    required: true
                },
                startTime: {
                    required: true
                },
                endTime: {
                    required: true
                }
            },
            messages: {
                activityName: {
                    required: icon + "活动名称不能为空"
                },
                startTime: {
                    required: icon + "开始时间不能为空"
                },
                endTime: {
                    required: icon + "结束时间不能为空"
                }
            }
        })
    }


    function saveProduct() {
        var sku = localStorage.getItem("productSKU");

        var activityName = $("#activityName").val();
        if (!activityName) {

            layer.tips("活动名称不能为空", '#activityName', {time: 2000, tips: 2});

            $("#activityName").focus();
            return;
        }
        var startTime = $("#startTime").val();
        if (!startTime) {
            layer.tips("开始时间不能为空", '#startTime', {time: 2000, tips: 2});

            $("#startTime").focus();
            return;
        }
        var endTime = $("#endTime").val();
        if (!endTime) {
            layer.tips("结束时间不能为空", '#endTime', {time: 2000, tips: 2});
            toastr.error("结束时间不能为空");
            $("#endTime").focus();
            return;
        }

        var rule = $("input[name='rule']:checked").val();
        var mode = $("input[name='mode']:checked").val();
        var cond = $("#cond").val();

        //赠品商品列表
        var giftProductList = $("#giftProductListTable").bootstrapTable('getData');//行的数据
        var giftProductSkuList = localStorage.getItem("productSKU");

        var joinNum = $("#joinNum").val();
        var range = $("input[name='range']:checked").val();
        var joinProductList = $("#joinProductListTable").bootstrapTable('getData');//行的数据
        var joinProductSkuList = localStorage.getItem("joinProductSKU");


        // var centreId = this.row.centreId;
        // var teamId = this.row.liansuoid;

        // var productName = this.row.title;
        // var thumb = this.row.thumb;
        //
        // var groupPrice = $("#groupPrice").val();
        // var stock = $("#stock").val();
        // var needJoinGroupNum = $("#needJoinGroupNum").val();

        var centerId = '';
        var teamId = '';
        var data = {
            id: $("#activityId").val(),
            centreId: centerId,
            teamId: teamId,
            activityName: activityName,
            startTime: startTime,
            endTime: endTime,
            rule: rule,
            mode: mode,
            cond: cond,
            giftProductList: giftProductList,
            giftProductSkuList: giftProductSkuList,
            joinNum: joinNum,
            range: range,
            joinProductList: joinProductList,
            joinProductSkuList: joinProductSkuList
        }

        var giftProductArray = [];
        if (giftProductList) {
            // var giftProductListJson = JSON.parse(giftProductList);
            for (var i = 0; i < giftProductList.length; i++) {
                var tempProduct = giftProductList[i];
                if (centerId == '' || !centerId) {
                    centerId = tempProduct.centreId;
                }
                if (teamId == '' || !teamId) {
                    teamId = tempProduct.teamId;
                }
                // var product = {
                //     productId: tempProduct.id,
                //     productName: tempProduct.title
                // }
                giftProductArray.push(tempProduct);
            }
        }
        data.giftProductList = giftProductArray;

        var giftProductSkuArray = [];
        if (giftProductSkuList) {
            var giftProductSkuListJson = JSON.parse(giftProductSkuList);
            for (var i = 0; i < giftProductSkuListJson.length; i++) {
                var tempSku = giftProductSkuListJson[i];
                if (centerId == '' || !centerId) {
                    centerId = tempSku.centreId;
                }
                if (teamId == '' || !teamId) {
                    teamId = tempSku.teamId;
                }
                var sku = {
                    id: tempSku.id,
                    productCentreId: tempSku.productCentreId,
                    centreId: tempSku.centreId,
                    teamId: tempSku.teamId,
                    skuId: tempSku.id,
                    title: tempSku.title,
                    thumb: tempSku.thumb,
                    groupPrice: tempSku.groupPrice,
                    specs: tempSku.specs,
                    stock: tempSku.stock,
                    giftAmount: tempSku.giftAmount,
                    giftAllAmount: tempSku.giftAllAmount
                }
                giftProductSkuArray.push(sku);
            }
        }
        data.giftProductSkuList = giftProductSkuArray;

        var joinProductArray = [];
        if (joinProductList) {
            // var joinProductListJson = JSON.parse(joinProductList);
            for (var i = 0; i < joinProductList.length; i++) {
                var tempProduct = joinProductList[i];
                if (centerId == '' || !centerId) {
                    centerId = tempProduct.centreId;
                }
                if (teamId == '' || !teamId) {
                    teamId = tempProduct.teamId;
                }
                // var product = {
                //     productId: tempProduct.id,
                //     productName: tempProduct.title
                // }
                joinProductArray.push(sku);
            }
        }
        data.joinProductList = joinProductArray;

        var joinProductSkuArray = [];
        if (joinProductSkuList) {
            var joinProductSkuListJson = JSON.parse(joinProductSkuList);
            for (var i = 0; i < joinProductSkuListJson.length; i++) {
                var tempSku = joinProductSkuListJson[i];
                if (centerId == '' || !centerId) {
                    centerId = tempSku.centreId;
                }
                if (teamId == '' || !teamId) {
                    teamId = tempSku.teamId;
                }
                var sku = {
                    id: tempSku.id,
                    productCentreId: tempSku.productCentreId,
                    centreId: tempSku.centreId,
                    teamId: tempSku.teamId,
                    skuId: tempSku.id,
                    title: tempSku.title,
                    thumb: tempSku.thumb,
                    groupPrice: tempSku.groupPrice,
                    specs: tempSku.specs,
                    stock: tempSku.stock,
                    giftAmount: tempSku.giftAmount,
                    giftAllAmount: tempSku.giftAllAmount
                }
                joinProductSkuArray.push(sku);
            }
        }
        data.joinProductSkuList = joinProductSkuArray;
        data.centreId = centerId;
        data.teamId = teamId;

        $.ajax({
            url: '/activity/manage/saveActivity',
            contentType: "application/json",
            dataType: "json",
            type: 'POST',
            data: JSON.stringify(data),
            success: function (result) {
                if (result.code == 0) {
                    layer.alert("保存成功", {icon: 6});
                } else {
                    if (result.msg != "" && result.msg != null) {
                        layer.alert(result.msg, {icon: 5});
                    } else {
                        layer.alert("保存失败，请联系管理员", {icon: 5});
                    }

                }
            }
        })
    }


</script>

</body>
</html>
